import "DPI-C" function void submit_inst( input longint pc, input int inst, input longint next_pc);
import "DPI-C" function void raise_hard_intr();
import "DPI-C" function void difftest_memory_access(input longint addr);
module difftest(
  input clk,
  input rst,
  input [4:0] data_valid,
  input writeback_enable,
  input [31:0] writeback_inst,
  input writeback_difftest_raise_hard_intr,
  input [1:0] writeback_other_op,
  input difftest_memory_op_i,
  input [63:0] difftest_memory_addr_i,
  input [63:0] fetch_pc,decode_pc,execute_pc,memory_pc,writeback_pc

);
import "DPI-C" function void other_inst(input bit ecall, input bit fence, input bit ebreak );
wire op_fence, op_ebreak;
assign {op_fence,op_ebreak} = writeback_other_op;
  reg [63:0] next_pc;
  reg submit;
  reg [63:0] pc;
  reg [31:0] inst;
  always @(posedge clk) begin
    if(writeback_enable) submit_inst(pc,inst,next_pc);
    if(writeback_enable&(|writeback_other_op)) other_inst(1'b0,op_fence,op_ebreak);

    if(writeback_enable&writeback_difftest_raise_hard_intr) raise_hard_intr();
    if(writeback_enable&difftest_memory_op_i) difftest_memory_access(difftest_memory_addr_i);
  end

  always @(*) begin
    submit = writeback_enable;
    inst = writeback_inst;
    pc = writeback_pc;
    next_pc = fetch_pc;
    if(data_valid[1]) next_pc = decode_pc;
    if(data_valid[2]) next_pc = execute_pc;
    if(data_valid[3]) next_pc = memory_pc;

  end
endmodule
